package com.lifei.controller;

import com.lifei.es.service.PositionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;
import java.util.Map;

@Controller
public class PositionController {

    @Autowired
    private PositionService positionService;

    //测试范文页面
    @GetMapping({"/","index"})
    public String indexPage(){
        return "index";
    }

    @GetMapping("/search/{keyword}/{pageNo}/{pageSize}")
    @ResponseBody
    public List<Map<String, Object>> searchPosition(@PathVariable("keyword") String keyword ,
                                                    @PathVariable("pageNo") int pageNo,
                                                    @PathVariable("pageSize") int pageSize) throws IOException {
        List<Map<String,Object>> list = positionService.searchPos(keyword,pageNo,pageSize);
        System.out.println(list);
        return list;
    }



    @RequestMapping("/importAll")
    @ResponseBody
    public String importAll(){
        try {
            positionService.importAll();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "success";
    }

}
